package com.tourManagement.service.impl;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.handler.BeanHandler;
import cn.hutool.db.sql.Condition;
import cn.hutool.db.sql.SqlUtil;
import com.tourManagement.entity.Notice;
import com.tourManagement.entity.User;
import com.tourManagement.service.NoticeService;
import com.tourManagement.service.UserService;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * Author:grass
 * Date:2022/10/16 0016
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    @Override
    public List<Notice> select() throws SQLException {
        return Db.use().findAll(Entity.create("tb_notice"), Notice.class);
    }

    @Override
    public List<Notice> selectByContent(String content) throws SQLException {

        List<Notice> all = Db.use().findAll(Entity.create("tb_notice").set("content", SqlUtil.buildLikeValue(content, Condition.LikeType.Contains, true)), Notice.class);
        return all;
    }

    @Override
    public int updateContent(Notice notice) throws SQLException {
        return Db.use().update(Entity.create("tb_notice").parseBean(notice, true, true), Entity.create("tb_notice").set("id", notice.getId()));

    }

    @Override
    public int updateTitle(Notice notice) throws SQLException {
        return Db.use().update(Entity.create("tb_notice").parseBean(notice, true, true), Entity.create("tb_notice").set("id", notice.getId()));
    }

    @Override
    public int insert(Notice notice) throws SQLException {
        System.out.println(notice);
        return Db.use().insert(Entity.create("tb_notice").parseBean(notice));

    }

    /*根据id删除
    * */
    @Override
    public int delete(int id) throws SQLException {
        return Db.use().del(Entity.create("tb_notice").set("id", id));

    }

}
